//  诱导用户打开通知消息
export default function() {
	uni.getPushClientId({
		success: res => {
			console.log(res);
			console.log(res.cid);
		}
	})
	uni.onPushMessage((res) => {
		console.log('收到推送消息', res);
		const {
			data
		} = res
		console.log('收到推送消息data', data);
		/*
		boxId： 盒子id
		sourceType：source
		zid：今日限定盒子传
		创建通知栏消息,并监听到推送时显示
		 */
		let payloadParams = {
			boxld: data.boxld || '',
			sourceType: data.sourceType || '',
			zid: data.zid || ''
		}
		// 创建通知栏消息
		if (res.type === 'receive') {
			uni.createPushMessage({
				title: data.title,
				content: data.content,
				payload: payloadParams,
				cover: false
				// sound: "system",
				// cover: true
			})
		} else if (res.type === 'click') {
			console.log(res);
			const {
				boxld,
				sourceType,
				zid
			} = data.payload
			/* 普通盒子 */
			if (boxld && !sourceType) {
				uni.navigateTo({
					url: '/pages/home/kaixiang?id=' + boxld
				});
				return false;
			}
			/* 周几限定 */
			if (boxld && sourceType === 8) {
				uni.navigateTo({
					url: '/pages/home/kaixiang?id=' + boxld + '&boxSource=' + sourceType + '&zid=' + params.zid
				});
				return false;
			}
			/* 活动盒子 */
			if (boxld && sourceType) {
				uni.navigateTo({
					url: '/pages/home/kaixiang?id=' + boxld + '&boxSource=' + sourceType 
				});
				return false;
			}
			uni.navigateTo({
				url: 'pages/tabBar/home' 
			});
			// if (source === 8) {
			// 	/* 今日限定活动需要zid */
			// 	let zid = params.id; // 限定用
			// 	uni.navigateTo({
			// 		url: '/pages/home/kaixiang?id=' + params.bindboxid + '&music=' + this.muteBgMusic + '&boxSource=' + source + '&zid=' + params.id
			// 	});
			// 	return false;
			// }
			// if (source) {
			// 	uni.navigateTo({
			// 		url: '/pages/home/kaixiang?id=' + id + '&music=' + this.muteBgMusic + '&boxSource=' + source
			// 	});
			// } else {
			// 	console.log(params, 'paramsparamsparams');
			// 	uni.navigateTo({
			// 		url: '/pages/home/kaixiang?id=' + id + '&music=' + this.muteBgMusic
			// 	});
			// }
			// uni.navigateTo({
			// 	url: '/pages/shoppingDemo/shoppingDemo?id=' + data.payload.id
			// })
		}
	})
}